package com.fzy.core.system.action;

import ge.core.system.entity.Entity;
import ge.core.system.entity.Mapping;
import ge.core.system.service.MappingListVo;

import java.util.List;

import com.fzy.core.entity.Page;
import com.fzy.core.system.service.DbService;
import com.fzy.core.system.service.EntityQuery;
import com.fzy.core.utils.NumberUtils;
import com.fzy.core.utils.U;
import com.fzy.core.webwork.BaseAction;
import com.opensymphony.xwork.Preparable;

public class TableListAction extends BaseAction implements Preparable {
	Page page;
	EntityQuery entityQuery;
	DbService dbService;
	List mappingList;
	Mapping mapping;
	Entity defaultEntity;
	public void prepare() throws Exception {
		entityQuery = new EntityQuery();
		page = new Page();
		String mappingIdString = request.getParameter("mapping.id");
		Long mappingId = NumberUtils.createLongSafely(mappingIdString);
		if(mappingId != null)
			mapping = (Mapping)U.getBaseService().get(Mapping.class, mappingId);
		if(mapping == null)
			mapping = new Mapping();
		defaultEntity = new Entity();
		defaultEntity.setPackageText("ge.app");
		defaultEntity.setHasPrefix("0");
		defaultEntity.setIsWork("1");
	}
	public String execute() throws Exception {
//		page = dbService.getTables(mapping.getNameText(), entityQuery, page);
		mappingList = dbService.getMappings();
		MappingListVo vo = new MappingListVo();
		vo.setId(new Long(0));
		vo.setNameText("请选择");
		mappingList.add(0, vo);
		
		return "dispatcher:/WEB-INF/jsp/core/system/table-list.jsp";
    }
	public Page getPage() {
		return page;
	}
	public EntityQuery getEntityQuery() {
		return entityQuery;
	}
	public void setDbService(DbService dbService) {
		this.dbService = dbService;
	}
	public List getMappingList() {
		return mappingList;
	}
	public Mapping getMapping() {
		return mapping;
	}
	public Entity getDefaultEntity() {
		return defaultEntity;
	}
}
